package com.fyy.socket.tcp.upload;

import java.io.*;
import java.net.Socket;

/**
 * @Author fyy
 * @Description 文件上传客户端
 * @Date 2020/12/15 15:14
 */
public class UpClient {

    public static void main(String[] args) throws IOException {
        String sFilePath = "F:\\test.txt";
        Socket socket = new Socket("127.0.0.1",8088);
        try ( //创建文件输入输出流
              BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sFilePath));
              BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        ){
            //读取文件
            byte[] buf = new byte[1024];
            int len;
            while ((len = bis.read(buf)) != -1){
                bos.write(buf,0,len);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
